<template>
	<view>
		<view v-if='agree == true'>
			<view style='padding:10px;'>
				<u--form label-width='100px;'>
					<u-form-item label="真实姓名" borderBottom ref="item1">
						<u--input v-model="realname" border="none"></u--input>
					</u-form-item>
					<u-form-item label="身份证号" borderBottom ref="item1">
						<u--input v-model="idCardNo" border="none"></u--input>
					</u-form-item>
					<u-form-item label="银行卡号" borderBottom ref="item1">
						<u--input v-model="cardNo" border="none" ></u--input>
					</u-form-item>
					<u-form-item label="预留手机" borderBottom ref="item1">
						<u--input v-model="phone" border="none"></u--input>
					</u-form-item>
				</u--form>
				<u-datetime-picker :show="show" v-model="value" mode="date" @close='show = false' @cancel='show = false' @confirm='choosedDate' :minDate='minDate' :maxDate='maxDate' ></u-datetime-picker>
			</view>
			<view class='footer'>
				<view style='padding:10px;'>
					<u-button size='large' type='error' text='保存' @click='save'></u-button>
				</view>
			</view>
		</view>
		<view v-else>
			<view style='padding:10px 10px 50px 10px'>
				<view style='color:#303133;font-weight:bold;text-align: center;padding-bottom:10px'>《{{contentTitle}}》
				</view>
				<u-parse :content="content"></u-parse>
			</view>
			<view style='position: fixed;width:100%;bottom:0px;background-color: #fff;'>
				<u-row>
					<u-col :span='6'>
						<view style='padding:10px'>
							<u-button size='large' text='不同意' @click='toUrl("/pages/wallet/index")'></u-button>
						</view>
					</u-col>
					<u-col :span='6'>
						<view style='padding:10px'>
							<u-button size='large' type='primary' text='同意' @click='toAgree'></u-button>
						</view>
					</u-col>
				</u-row>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '',
				title: '温馨提示',
				cardNo: '',
				phone: '',
				code: '',
				showBankName: '点击选择',
				bankCode: '910290000028',
				status: 1,
				realname: '',
				idCardNo: '',
				banks: [],
				show: false,
				bankName: '（CIPS专用）中国农业银行股份有限公司',
				agree: false,
				content: '',
				contentTitle: '',
				beginDate: '20150101',
				endDate: '20350101',
				show: false,
				isLong: false,
				chooseType: 'begin',
				minDate: '2000-01-01',
				maxDate: '2050-12-31'
			}
		},
		onShow() {
			let minDate = new Date('2000-01-01')
			this.minDate = minDate.getTime()
			let maxDate = new Date('2050-01-01')
			this.maxDate = maxDate.getTime()
			this.request.get(`api/huifu-accounts`).then((res) => {
				console.log('汇付账号',res.data)
				if (res.data.length > 0) {
					uni.showModal({
						title: '',
						content: '您已经绑定了相关账号，无需重新绑定！',
						showCancel: false,
						success: () => {
							uni.switchTab({
								url: '/pages/mine/index'
							})
						}
					})
				}
			})
		},
		onLoad() {
			this.request.get(`api/contents/2`).then((res) => {
				console.log(res.data)
				this.content = res.data.content
				this.contentTitle = res.data.title
			})
		},
		methods: {
			toAgree() {
				uni.showModal({
					title: '',
					content: '我们将按业界成熟得安全标准，采取相应的安全保护措施来保护您的个人信息。',
					showCancel: false,
					success: () => {
						this.agree = true
					}
				})
			},
			save() {
				uni.showLoading()
				if (this.cardNo == '' || this.phone == '' || this.realname.trim() == '' || this.idCardNo.trim() == '' || this.beginDate == '') {
					uni.showToast({
						title: '请填写相关信息！',
						icon: 'none'
					})
				} else {
					// 判断银行卡以及手机号码
					this.cardNo = this.cardNo.replace(/\ +/g, '')
					this.phone = this.phone.replace(/\ +/g, '')
					const cardInfo = {
						card_no: this.cardNo,
						mp: this.phone,
						card_name: this.realname,
						cert_no: this.idCardNo,
						card_type: 1,
						prov_id: '310000',
						area_id: '310100',
						band_code: '01030000',
						cert_type: '00',
						cert_validity_type: this.isLong ? 1 : 0,
						cert_begin_date: this.beginDate,
						cert_end_date: this.endDate
					}
					let postData = {
						mobile_no: this.phone,
						card_info: cardInfo,
					}
					console.log('date', postData)
					this.request.post(`api/huifu-accounts/register/individual-user`, postData).then((res) => {
						uni.hideLoading()
						uni.showModal({
							title: '提示',
							content: '绑定成功！',
							showCancel: false,
							success: () => {
								uni.redirectTo({
									url: '/pages/mine/index'
								})
							}
						})
					}).catch((err) => {
						uni.hideLoading()
					})
				}

			}
		}
	}
</script>

<style>

</style>